package com.zwface.demo.function.leave;

import android.view.View;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProviders;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.blankj.utilcode.util.TimeUtils;
import com.zwface.demo.R;
import com.zwface.demo.base.BaseActivity;
import com.zwface.demo.databinding.ActivityLeaveBinding;
import com.zwface.demo.function.leave.mvvm.LeaveViewModel;

import java.util.Date;

/**
 * created by      张中文
 * on:             2020/4/29 10:15
 * 描述：请假
 */
public class LeaveActivity extends BaseActivity<ActivityLeaveBinding> implements View.OnClickListener {
    private LeaveViewModel viewModel;
    TimePickerView pvTime;
    TextView curTextview;

    @Override
    public int onLayoutId() {
        return R.layout.activity_leave;
    }

    @Override
    public void onInitViewDataBinding(ActivityLeaveBinding binding) {
        super.onInitViewDataBinding(binding);
        viewModel = ViewModelProviders.of(this).get(LeaveViewModel.class);
        binding.setData(viewModel);
    }

    @Override
    public void onInitComponent() {
        super.onInitComponent();
        initTopbar();

        //时间选择器
        pvTime = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                String time = TimeUtils.date2String(date,"MM-dd HH:mm");
                curTextview.setText(time);
            }
        }).setType(new boolean[]{false, true, true, true, true, false})// 默认全部显示
          .setLabel("年","月","日","时","分","秒")//默认设置为年月日时分秒
         .build();

        binding.tvTimeStart.setOnClickListener(this);
        binding.tvTimeEnd.setOnClickListener(this);
        binding.btnSubmit.setOnClickListener(this);
    }

    private void initTopbar(){
        binding.topbar.setTitle("我要请假");
        binding.topbar.addLeftBackImageButton().setOnClickListener(view -> finish());
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_time_start:
            case R.id.tv_time_end:
                curTextview = (TextView) view;
                pvTime.show();
                break;
            case R.id.btn_submit:
                viewModel.submitLeave();
                break;
        }
    }
}
